var sql = require('./sql');
var block = require('./blockChain');

module.exports = {
    'POST /register': async (ctx, next) => {

        var
            email = ctx.request.body.email || '',
            password = ctx.request.body.password || '',
            name = ctx.request.body.password || '',
            phone = ctx.request.body.password || '',
            //异步得到数据库查询的值，此处返回一个promise
            account = await sql.getNext();
        account = block.query.getNextAddress(account);
        console.log(account);
        if (account != '') {
            block.query.UserRegister(name,phone,account);
            sql.register(email,password,name,account,phone);
            ctx.render('register-ok.html', {
                title: 'Register OK',
                name: 'OK',
                address: account
            });
        } else {
            console.log('register failed!');
            ctx.render('signin-failed.html', {
                title: 'Sign In Failed'
            });
        }
    }
};

